package com.wentao.thisService.controller;

import com.wentao.thisCommon.annotation.MethodAuthority;
import com.wentao.thisCommon.model.RequestBase;
import com.wentao.thisCommon.model.ResultBase;
import com.wentao.thisFacade.business.BaseCtrInterface;
import com.wentao.thisFacade.common.enums.ExceptionCode;
import com.wentao.thisFacade.common.enums.SuccessCode;
import com.wentao.thisFacade.domain.reqeust.*;
import com.wentao.thisFacade.domain.result.*;
import com.wentao.thisService.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BaseController implements BaseCtrInterface {
    @Autowired
    private CommunalService communalService;

    @Autowired
    private CompanyService companyService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private LocationService locationService;

    @Autowired
    private PartnerService partnerService;

    /**
     * @see BaseCtrInterface#searchSettingList(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
//    @MethodAuthority(permissionCode = {"ADMIN_ALLOW_FUNC"})
    public ResultBase<List<SettingMapResult>> searchSettingList(@RequestBody RequestBase<SearchSettingListRequest> entity) {
        try {
            List<SettingMapResult> settingMapResultList = communalService.searchSettingList(entity);
            return ResultBase.ok(settingMapResultList, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#searchSettingList(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<CompanyCustomPageResult> searchHotelGetRegList(RequestBase<HotelPageRequest> entity) {
        try {
            CompanyCustomPageResult companyCustomPageResult = companyService.searchHotelGetRegList(entity.getBody());
            return ResultBase.ok(companyCustomPageResult, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#searchHotelGetInfo(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<CompanyCustomResult> searchHotelGetInfo(RequestBase<HotelInfoRequest> entity) {
        try {
            CompanyCustomResult companyCustomResult = companyService.hotelDetails(entity.getBody().getCompanyCode());
            return ResultBase.ok(companyCustomResult, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#verifyCompany(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<Boolean> verifyCompany(RequestBase<VerifyCompanyRequest> entity) {
        try {
            Boolean flag = companyService.verifyCompany(entity.getBody(), Long.valueOf(entity.getUserId()));
            return ResultBase.ok(flag, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#basePageOrder(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<OrderInfoPageResult> basePageOrder(RequestBase<SearchOrderPageRequest> entity) {
        try {
            OrderInfoPageResult orderInfoPageResult = orderService.pageOrder(entity.getBody().getPageEntity());
            return ResultBase.ok(orderInfoPageResult, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }


    /**
     * @see BaseCtrInterface#baseOrderInfo(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<OrderInfoResult> baseOrderInfo(RequestBase<SearchOrderInfoRequest> entity) {
        try {
            OrderInfoResult orderInfoResult = orderService.orderInfo(Long.valueOf(entity.getBody().getOrderId()));
            return ResultBase.ok(orderInfoResult, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#orderDeliver(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<OrderInfoResult> orderDeliver(RequestBase<OrderDeliverRequest> entity) {
        try {
            OrderInfoResult orderInfoResult = orderService.orderDeliver(entity.getBody());
            return ResultBase.ok(orderInfoResult, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#listThreeLevelLocation()
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<List<LocationProvinceResult>> listThreeLevelLocation() {
        try {
            List<LocationProvinceResult> provinceResultList = locationService.listThreeLevelLocation();
            return ResultBase.ok(provinceResultList, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }


    /**
     * @see BaseCtrInterface#pagePartner(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<PartnerPageResult> pagePartner(RequestBase<PartnerRequest> entity) {
        try {
            PartnerPageResult partnerPageResult = partnerService.pagePartner(entity.getBody());
            return ResultBase.ok(partnerPageResult, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#listParentPartnerByLocation(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<List<PartnerResult>> listParentPartnerByLocation(RequestBase<PartnerRequest> entity) {
        try {
            List<PartnerResult> partnerResultList = partnerService.listParentPartnerByLocation(entity.getBody());
            return ResultBase.ok(partnerResultList, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#savePartner(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<Boolean> savePartner(RequestBase<PartnerRequest> entity) {
        try {
            Boolean flag = partnerService.savePartner(entity.getBody());
            return ResultBase.ok(flag, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#updatePartner(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<Boolean> updatePartner(RequestBase<PartnerRequest> entity) {
        try {
            Boolean flag = partnerService.updatePartner(entity.getBody());
            return ResultBase.ok(flag, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }

    /**
     * @see BaseCtrInterface#deletePartner(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<Boolean> deletePartner(RequestBase<PartnerRequest> entity) {
        try {
            Boolean flag = partnerService.deletePartner(entity.getBody());
            return ResultBase.ok(flag, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }


    /**
     * @see BaseCtrInterface#performanceList(RequestBase)
     */
    @SuppressWarnings("unchecked")
    @Override
    public ResultBase<PerformanceVal> performanceList(RequestBase<PerformanceListRequest> entity) {
        try {
            PerformanceVal performanceVal = partnerService.performanceList(entity.getBody());
            return ResultBase.ok(performanceVal, SuccessCode.SYSTEM_SUCCESS);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultBase.ok(ExceptionCode.ON_FAILURE);
        }
    }
}
